package org.elanfox.intellicommunity.intellicommunityadmin.controller.statistics;

import org.elanfox.intellicommunity.biz.entity.statistics.AlarmStatisticsPO;
import org.elanfox.intellicommunity.biz.service.core.statistics.AlarmStatisticsService;
import org.elanfox.intellicommunity.common.utils.Jsr310Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author loutianxi
 * @date 2019-12-08
 */
@Controller
@RequestMapping("/statistic")
public class StatisticController {
    @Autowired
    private AlarmStatisticsService alarmStatisticsService;

    @RequestMapping(value = {"/count"})
    public String toMapUserList(Model model, @RequestParam(defaultValue = "1") Integer strId) {
        model.addAttribute("strId", strId);

        List<AlarmStatisticsPO> alarmData = alarmStatisticsService.sevenDays();
        List<String> dates = alarmData.stream()
                .map(p -> Jsr310Utils.Date.asString(p.getDate())).collect(Collectors.toList());
        model.addAttribute("alarmData", alarmData);
        model.addAttribute("dates", dates);

        return "map/statistics";
    }
}
